import axios from '@/libs/api.request'

export const login = ({ username, password }) => {
  const data = {
    username,
    password
  };
  return axios.request({
    url: 'api/HttpAutoTestService/token',
    data,
    method: 'post'
  })
};

export const getUserNames = (val) => {
  return axios.request({
    url: 'api/HttpAutoTestService/user/names/',
    params: val,
    method: 'get'
  })
};

export const getUsers = (val) => {
  return axios.request({
    url: 'api/HttpAutoTestService/users/',
    params: val,
    method: 'get'
  })
};

export const getUser = (id) => {
  return axios.request({
    url: `api/HttpAutoTestService/users/${id}/`,
    method: 'get'
  })
};

export const createUser = (user) => {
  return axios.request({
    url: 'api/HttpAutoTestService/user/',
    data: user,
    method: 'post'
  })
};

export const updateUser = (user) => {
  return axios.request({
    url: `api/HttpAutoTestService/user/${user.id}/`,
    data: user,
    method: 'patch'
  })
};

export const activeUser = (data) => {
  return axios.request({
    url: `api/HttpAutoTestService/user/${data.id}/`,
    data: { is_active: data.is_active },
    method: 'patch'
  })
};

export const deleteUser = (id) => {
  return axios.request({
    url: `api/HttpAutoTestService/user/${id}/`,
    method: 'delete'
  })
};

export const changePwd = (data) => {
  return axios.request({
    url: `api/HttpAutoTestService/pwd/${data.id}/`,
    data,
    method: 'put'
  })
};

export const resetPwd = (id) => {
  return axios.request({
    url: `api/HttpAutoTestService/pwd/${id}/`,
    data: { id: id },
    method: 'patch'
  })
};
